package com.koala.aideddevsystemmodule.modules.rabbitMQ.controller;

import com.koala.aideddevsystemmodule.modules.rabbitMQ.entity.RabbitMQEntity;
import com.koala.aideddevsystemmodule.utils.R;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create by koala on 2022-08-21
 */
@RestController
@RequestMapping("/rabbitMQ")
public class MQController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 测试RabbitMQ延时队列
     * 测试：
     * 结果监听在 com.koala.aideddevsystemmodule.rabbitMQ.config.MyMQConfig listener() 方法中
     */
    @RequestMapping("/delayQueue")
    public R delayQueue() {
        RabbitMQEntity rabbitMQEntity = new RabbitMQEntity();
        rabbitMQEntity.setName("测试RabbitMQ延时队列");

        //给mq发消息
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", rabbitMQEntity);

        return R.ok();
    }

}